import pandas as pd
import numpy as np
import json

result = []


def import_industry():
    """
    导入行业实体
    :return:
    """
    with open('./big_category.csv', mode='r') as f:
        data_list = f.read().split('\n')
        for item in data_list:
            item = item.split()
            node_id = item[0]
            name = item[1]
            try:
                description = item[2]
            except:
                description = None
            temp = {'node_id': node_id, 'name': name, 'description': description}
            result.append(temp)
        print({'data': result})
    with open('./big_category.json', mode='w', encoding='utf-8') as f:
        json.dump({'data': result}, f, ensure_ascii=False)


def import_institute():
    with open('./institute.csv', mode='r') as f:
        data_list = f.read().split('\n')
        i = 1
        for item in data_list:
            item = item.split()
            node_id = str(i)
            name = item[0]

            temp = {'node_id': node_id, 'name': name, 'description': None}
            i += 1
            result.append(temp)
        print({'data': result})
    with open('./institute.json', mode='w', encoding='utf-8') as f:
        json.dump({'data': result}, f, ensure_ascii=False)


def import_major():
    with open('./major.csv', mode='r') as f:
        data_list = f.read().split('\n')
        i = 1
        for item in data_list:
            item = item.split()
            node_id = str(i)
            name = item[0]

            temp = {'node_id': node_id, 'name': name, 'description': None}
            i += 1
            result.append(temp)
        print({'data': result})
    with open('./major..json', mode='w', encoding='utf-8') as f:
        json.dump({'data': result}, f, ensure_ascii=False)



def import_classes():
    with open('./classes.csv', mode='r') as f:
        data_list = f.read().split('\n')
        i = 1
        for item in data_list:
            item = item.split()
            node_id = str(i)
            name = item[0]

            temp = {'node_id': node_id, 'name': name, 'description': None}
            i += 1
            result.append(temp)
        print({'data': result})
    with open('./classes.json', mode='w', encoding='utf-8') as f:
        json.dump({'data': result}, f, ensure_ascii=False)


def import_institute_major():
    with open('./institute_major.csv', mode='r') as f:
        data_list = f.read().split('\n')
        for item in data_list:
            item = item.split()
            institute = item[0]
            major = item[1]
            temp = { 'institute': institute, 'major': major}
            result.append(temp)
        print({'data': result})
    with open('./institute_major.json', mode='w', encoding='utf-8') as f:
        json.dump({'data': result}, f, ensure_ascii=False)


def import_major_classes():
    with open('./major_classes.csv', mode='r') as f:
        data_list = f.read().split('\n')
        for item in data_list:
            item = item.split()
            major = item[0]
            classes = item[1]
            temp = { 'major': major, 'classes': classes}
            result.append(temp)
        print({'data': result})
    with open('./major_classes.json', mode='w', encoding='utf-8') as f:
        json.dump({'data': result}, f, ensure_ascii=False)


def import_students():
    """
    生成学生信息
    :return:
    """
    with open('./students.csv', mode='r') as f:
        data_list = f.read().split('\n')
        i = 1
        for item in data_list:
            item = item.split()
            node_id = str(i)
            name = item[0]

            temp = {'node_id': node_id, 'name': name, 'description': None}
            i += 1
            result.append(temp)
        print({'data': result})
    with open('./classes.json', mode='w', encoding='utf-8') as f:
        json.dump({'data': result}, f, ensure_ascii=False)



if __name__ == '__main__':
    # 导入学院信息
    # import_institute()
    # import_major()
    # import_classes()
    # import_institute_major()
    import_major_classes()